package com.sql.common.intc.impl;

import com.sql.common.intc.SqlTypeConvert;

import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.util.Date;

public class DefaultTimeConvert implements SqlTypeConvert {
    private static final SimpleDateFormat formater = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    @Override
    public Object convert(Object data) {
        if(data == null) return null;
        if(data instanceof Timestamp){
            Date date = new Date(((Timestamp)data).getTime());
            return formater.format(date);
        }else if(data instanceof java.sql.Date){
            Date date = new Date(((java.sql.Date)data).getTime());
            return formater.format(date);
        }
        return data;
    }
}
